package org.example5;

public class SLList {


    /*
    the first item if it exists is sentinel.next
     */
    private IntNode sentinel;
    private int size; //cache size

    public SLList() {
        sentinel = new IntNode(63,null);

        size  = 0;
        //first = null;
    }
    public SLList(int x) {
        sentinel = new IntNode(63,null);
        sentinel.next = new IntNode(x,null);
        size = 1;
    }

    public void addFirst(int x) {
        sentinel.next = new IntNode(x,sentinel.next);

        size+=1;
    }

    public int getFirst() {
        return sentinel.next.item;
    }

    public void addLast(int x) {

        size+=1;


        IntNode p =  sentinel ;



        while(p.next!=null){
            p = p.next;
        }
        p.next = new IntNode(x,null);
    }

    /**
     *  return the size of
     * @return
     */
    private int size(IntNode p){
        if(p.next == null) {
            return 1;
        }
       return 1 + size(p.next);
    }
    public int size() {
        //return size(first);
        return size;
    }


    public static void main(String[] args){
        SLList L = new SLList();

        L.addLast(20);
        L.addLast(21);
        L.addLast(22);
       // System.out.println(L.get(1));
    }

    private static class IntNode {
        public int item;
        public IntNode next;



        public IntNode(int i, IntNode n) {
            item = i;
            next = n;
        }
    }

}
